package haemers.reflection.tests 
{
	import flash.utils.describeType;
	import haemers.reflection.data.vo.AccessorVO;
	import nl.haemers.data.constants.DataTypes;
	import nl.haemers.data.constants.ReflectionConstants;
	import nl.haemers.data.reflection.Accessor;
	import nl.haemers.data.reflection.Accessors;
	import nl.haemers.data.reflection.IMetadatas;
	import nl.haemers.data.reflection.Type;
	import org.flexunit.Assert;
	/**
	 * ...
	 * @author Jonathan
	 */
	public class AccessorTest 
	{
		private var _mockData:AccessorVO;
		
		private var _booleanAccessor:Accessor;
		private var _vectorAccessor:Accessor;
		private var _customObjectAccessor:Accessor;
		
		/** Public methods **/
		[Before]
		public function setup() : void
		{
			_booleanAccessor = new Accessor(_boolXML);
			_vectorAccessor = new Accessor(_vectorXML);
			_customObjectAccessor = new Accessor(_customObjectXML);
		}
		
		[Test]
		public function testBasicAccessor():void
		{
			Assert.assertEquals("haemers.data.vo::TestVO", _booleanAccessor.declaredBy);
			Assert.assertFalse(_booleanAccessor.hasSerialize());
			Assert.assertFalse(_booleanAccessor.ignore);
			Assert.assertNotNull(_booleanAccessor.metadatas);
			Assert.assertTrue(_booleanAccessor.metadatas is IMetadatas);
			Assert.assertEquals("human", _booleanAccessor.name);
			Assert.assertNull(_booleanAccessor.objectType);
			Assert.assertFalse(_booleanAccessor.overwriteable);
			Assert.assertEquals("human", _booleanAccessor.propertyName);
			Assert.assertEquals("human", _booleanAccessor.toString(), _booleanAccessor.name);
			Assert.assertTrue(_booleanAccessor.writeable);
		}
		
		[Test]
		public function testVectorAccessor() : void
		{
			Assert.assertNotNull(_vectorAccessor.objectType);
			Assert.assertTrue(_vectorAccessor.objectType is Type);
		}
		
		[Test]
		public function testCustomObject() : void
		{
			Assert.assertNotNull(_customObjectAccessor.objectType);
			Assert.assertTrue(_customObjectAccessor.objectType is Type);
		}
		
		[Test]
		public function testIgnoreAccessor() : void
		{
			Assert.assertTrue(_vectorAccessor.ignore);
		}
		
		[Test]
		public function testAccessorAccess() : void
		{
			Assert.assertEquals("readwrite", _booleanAccessor.acces, ReflectionConstants.READWRITE);
			Assert.assertEquals("readonly", _vectorAccessor.acces, ReflectionConstants.READONLY);
			Assert.assertEquals("writeonly", _customObjectAccessor.acces, ReflectionConstants.WRITEONLY);
		}
		
		[Test]
		public function testSerializeAccessor() : void
		{
			Assert.assertEquals("typedAccessors", _vectorAccessor.name);
			Assert.assertEquals("accessors", _vectorAccessor.propertyName);
			
			//TODO: Look for a method to compare 2 values which can't be equal!
		}
		
		[Test]
		public function testDataTypes() : void
		{
			Assert.assertEquals(DataTypes.BOOLEAN, _booleanAccessor.dataType);
			Assert.assertEquals(DataTypes.VECTOR, _vectorAccessor.dataType);
		}
		
		
		[After]
		public function teardown() : void
		{
			_booleanAccessor = null;
		}
		/** Getters & Setters **/
		
		/** Protected methods **/
		
		/** Private methods **/
		private var _boolXML:XML = new XML(
		<accessor name="human" access="readwrite" type="Boolean" declaredBy="haemers.data.vo::TestVO">
			<metadata name="__go_to_definition_help">
			  <arg key="pos" value="1356"/>
			</metadata>
			<metadata name="__go_to_definition_help">
			  <arg key="pos" value="1427"/>
			</metadata>
		</accessor>
		);
		
		private var _vectorXML:XML = new XML(
		<accessor name="accessors" access="readonly" type="__AS3__.vec::Vector.&lt;haemers.reflection.data.vo::AccessorVO>" declaredBy="haemers.data.vo::EnvironmentVO">
			<metadata name="Serialize">
			  <arg key="name" value="typedAccessors"/>
			  <arg key="ignore" value="true"/>
			</metadata>			
			<metadata name="__go_to_definition_help">
			  <arg key="pos" value="1303"/>
			</metadata>
			<metadata name="__go_to_definition_help">
			  <arg key="pos" value="1391"/>
			</metadata>
		</accessor>
		);
		
		private var _customObjectXML:XML = new XML(
		<accessor name="accessor" access="writeonly" type="haemers.reflection.data.vo::AccessorVO" declaredBy="haemers.reflection.data.vo::AccessorVO">
			<metadata name="Serialize">
			  <arg key="name" value="name"/>
			</metadata>			
			<metadata name="__go_to_definition_help">
			  <arg key="pos" value="1546"/>
			</metadata>
			<metadata name="__go_to_definition_help">
			  <arg key="pos" value="1664"/>
			</metadata>
		</accessor>
		);
	}

}